<style lang="less">
    @import "detail.less";
</style>
<template>


    <div>
        <Card style="width:100%" shadow>
            <Collapse  v-model="showPanel">
                <Panel name="1">
                    日志
                    <div slot="content">
                        <approveHistory ref="approveHistory" :Obj="approveHistoryObj"/>
                    </div>
                </Panel>
                <Panel name="2">
                    基本信息
                    <div slot="content">
                        <Form ref="baseInfo" :model="caseInfo" class="detailForm"
                              :label-width="100"
                              inline>
                            <Row>
                                <Col span="8">
                                    <FormItem prop="startTime" label="申请时间">
                                        <DatePicker type="date" v-model="caseInfo.startTime" disabled placeholder="选择日期"></DatePicker>
                                    </FormItem>
                                </Col>
                                <Col span="8">
                                    <FormItem prop="endTime" label="结束时间" >
                                        <DatePicker type="date" v-model="caseInfo.endTime" disabled placeholder="选择日期"></DatePicker>
                                    </FormItem>
                                </Col>
                                <Col span="8">
                                    <FormItem prop="createBy" label="创建人">
                                        <Input type="text" v-model="caseInfo.createTagStr" disabled placeholder="请输入">
                                        </Input>
                                    </FormItem>
                                </Col>
                            </Row>
                            <Row>
                                <Col span="8">
                                    <FormItem prop="caseNo" label="案件编号" >
                                        <Input type="text" v-model="caseInfo.caseNo" disabled placeholder="请输入">
                                        </Input>
                                    </FormItem>
                                </Col>
                                <Col span="8">
                                    <FormItem prop="caseSource" label="来源">
                                        <Select v-model="caseInfo.caseSource" disabled placeholder="请选择">
                                            <Option v-for="item in dataDic.businessSource" :label="item.title" :value="item.value" :key="item.value">{{ item.title }}</Option>
                                        </Select>
                                    </FormItem>
                                </Col>
                            </Row>
                        </Form>
                    </div>
                </Panel>
                <Panel name="3">
                    合同信息
                    <div slot="content">
                        <Form ref="contractInfo" :model="contractInfo" class="detailForm"
                              :label-width="100"
                              inline>
                            <Row>
                                <Col span="8">
                                    <FormItem prop="applyNo" label="申请编号" >
                                        <Input type="text" v-model="contractInfo.applyNo" disabled placeholder="请输入">
                                        </Input>
                                    </FormItem>
                                </Col>
                                <Col span="8">
                                    <FormItem prop="custName" label="客户姓名" >
                                        <Input type="text" v-model="contractInfo.custName" disabled placeholder="请输入">
                                        </Input>
                                    </FormItem>
                                </Col>
                                <Col span="8">
                                    <FormItem prop="certNo" label="证件号码" >
                                        <Input type="text" v-model="contractInfo.certNo" disabled placeholder="请输入">
                                        </Input>
                                    </FormItem>
                                </Col>

                            </Row>
                            <Row>
                                <Col span="8">
                                    <FormItem prop="phone" label="联系方式" >
                                        <Input type="text" v-model="contractInfo.phone" disabled placeholder="请输入">
                                        </Input>
                                    </FormItem>
                                </Col>
                                <Col span="8">
                                    <FormItem prop="startDate" label="合同激活时间" >
                                        <DatePicker type="date" v-model="contractInfo.startDate" disabled placeholder="选择日期"></DatePicker>
                                    </FormItem>
                                </Col>
                                <Col span="8">
                                    <FormItem prop="endDate" label="合同终止时间" >
                                        <DatePicker type="date" v-model="contractInfo.endDate" disabled placeholder="选择日期"></DatePicker>
                                    </FormItem>
                                </Col>
                            </Row>
                            <Row>
                                <Col span="8">
                                    <FormItem prop="contractStatus" label="合同状态" >
                                        <Select v-model="contractInfo.contractStatus" disabled placeholder="请选择">
                                            <Option v-for="item in dataDic.contractStatus" :label="item.title" :value="item.value" :key="item.value">{{ item.title }}</Option>
                                        </Select>
                                    </FormItem>
                                </Col>
                                <Col span="8">
                                    <FormItem prop="channelType" label="渠道归属" >
                                        <Select v-model="contractInfo.channelType" disabled placeholder="请选择">
                                            <Option v-for="item in dataDic.channelType" :label="item.title" :value="item.value" :key="item.value">{{ item.title }}</Option>
                                        </Select>
                                    </FormItem>
                                </Col>
                                <Col span="8">
                                    <FormItem prop="overdueDaysHis" label="当前逾期天数" >
                                        <Input type="text" v-model="caseInfo.overdueDays" disabled placeholder="请输入">
                                        </Input>
                                    </FormItem>
                                </Col>
                            </Row>
                            <Row>
                                <Col span="8">
                                    <FormItem prop="paidTerms" label="已还期数" >
                                        <Input type="text" v-model="contractInfo.paidTerms" disabled placeholder="请输入">
                                        </Input>
                                    </FormItem>
                                </Col>
                                <Col span="8">
                                    <FormItem prop="unpaidTerms" label="未还期数" >
                                        <Input type="text" v-model="contractInfo.unpaidTerms" disabled placeholder="请输入">
                                        </Input>
                                    </FormItem>
                                </Col>
                                <Col span="8">
                                    <FormItem prop="channelName" label="合作商" >
                                        <Input type="text" v-model="contractInfo.channelName" disabled placeholder="请输入">
                                        </Input>
                                    </FormItem>
                                </Col>
                            </Row>
                            <Row>
                                <Col span="8">
                                    <FormItem prop="paidTerms" label="月供金额" >
                                        <Input type="text" v-model="contractInfo.monthPayAmt" disabled placeholder="请输入">
                                        </Input>
                                    </FormItem>
                                </Col>
                                <Col span="8">
                                    <FormItem prop="unpaidTerms" label="当期总应收" >
                                        <Input type="text" v-model="contractInfo.currentReceivable" disabled placeholder="请输入">
                                        </Input>
                                    </FormItem>
                                </Col>
                                <Col span="8">
                                    <FormItem prop="channelName" label="上次付款时间" >
                                        <DatePicker type="date" v-model="contractInfo.lastPayTime" disabled placeholder="选择日期"></DatePicker>
                                    </FormItem>
                                </Col>
                            </Row>
                            <Row>
                                <Col span="8">
                                    <FormItem prop="channelName" label="利率类型" >
                                        <Select v-model="contractInfo.rateType" disabled placeholder="请选择">
                                            <Option v-for="item in dataDic.rateType" :label="item.title" :value="item.value" :key="item.value">{{ item.title }}</Option>
                                        </Select>
                                    </FormItem>
                                </Col>
                            </Row>
                        </Form>
                    </div>
                </Panel>
                <Panel name="4" v-show="this.obj.caseType == 'BEFORE_CHARGE'">
                    提前还款信息
                    <div slot="content">
                        <Form ref="prepaymentInfo" :model="prepaymentInfo" class="detailForm"
                              :label-width="100"
                              inline>
                            <Row>
                                <Col span="8">
                                    <FormItem prop="caseNo" label="案件编号" >
                                        <Input type="text" v-model="prepaymentInfo.caseNo" disabled placeholder="请输入">
                                        </Input>
                                    </FormItem>
                                </Col>
                                <Col span="8">
                                    <FormItem prop="receivableAmount" label="应收净额" >
                                        <Input type="text" v-model="prepaymentInfo.receivableAmount" disabled placeholder="请输入">
                                        </Input>
                                    </FormItem>
                                </Col>
                                <Col span="8">
                                    <FormItem prop="repayDate" label="结算日期" >
                                        <DatePicker type="date" v-model="prepaymentInfo.repayDate" disabled placeholder="选择日期"></DatePicker>
                                    </FormItem>
                                </Col>
                            </Row>
                            <Row>
                                <Col span="8" v-show="this.obj.caseType == 'BEFORE_CHARGE' && this.caseInfo.caseStatus && (this.caseInfo.caseStatus != 'NOT_SUBMIT' && this.caseInfo.caseStatus != 'UNDER_REVIEW')">
                                    <FormItem prop="debitOrderStatus" label="扣款指令" >
                                        <Select v-model="caseInfo.debitOrderStatus" disabled placeholder="请选择">
                                            <Option v-for="item in dataDic.validOrInvalid" :label="item.title" :value="item.value" :key="item.value">{{ item.title }}</Option>
                                        </Select>
                                    </FormItem>
                                </Col>
                                <Col span="8" v-show="this.obj.caseType == 'BEFORE_CHARGE' && (!this.caseInfo.caseStatus || this.caseInfo.caseStatus == 'NOT_SUBMIT' || this.caseInfo.caseStatus == 'UNDER_REVIEW')">
                                    <FormItem prop="debitOrderStatus" label="扣款指令" >
                                        <Select v-model="prepaymentInfo.debitOrderStatus" disabled placeholder="请选择">
                                            <Option v-for="item in dataDic.validOrInvalid" :label="item.title" :value="item.value" :key="item.value">{{ item.title }}</Option>
                                        </Select>
                                    </FormItem>
                                </Col>
                            </Row>
                        </Form>
                    </div>
                </Panel>
                <Panel name="5">
                    业务办理：{{setDictTitleByType("caseType",this.caseInfo.caseType)}}
                    <div slot="content">
                        <Form ref="caseInfo" :model="caseInfo" :rules="caseInfoFormValidate" class="detailForm"
                              :label-width="100"
                              inline>
                            <Row>
                                <Col span="8">
                                    <FormItem prop="receivingBank" label="收款银行">
                                        <Select v-model="caseInfo.receivingBank" disabled placeholder="请选择">
                                            <Option v-for="item in dataDic.bankCode" :label="item.title" :value="item.value" :key="item.value">{{ item.title }}</Option>
                                        </Select>
                                    </FormItem>
                                </Col>
                                <Col span="8">
                                    <FormItem prop="payAmt" label="打款金额" >
                                        <Input type="text" v-model="caseInfo.payAmt" disabled placeholder="请输入">
                                        </Input>
                                    </FormItem>
                                </Col>
                                <Col span="8">
                                    <FormItem prop="payTime" label="打款时间">
                                        <DatePicker type="date" v-model="caseInfo.payTime" disabled placeholder="选择日期"></DatePicker>
                                    </FormItem>
                                </Col>
                            </Row>
                            <Row>
                                <Col span="8">
                                    <FormItem prop="payer" label="打款人" >
                                        <Input type="text" v-model="caseInfo.payer" disabled placeholder="请输入">
                                        </Input>
                                    </FormItem>
                                </Col>
                            </Row>
                            <Row>
                                <Col span="24">
                                    <FormItem prop="remarks" label="说明">
                                        <Input type="text" class="holeLine" v-model="caseInfo.remarks" disabled placeholder="请输入">
                                        </Input>
                                    </FormItem>
                                </Col>
                            </Row>
                            <Row>
                                <Col span="24">
                                    <FormItem prop="images" label="打款凭证">
                                        <Button @click="openUploadModal" type="primary" icon="ios-cloud-upload" >凭证查看</Button>
                                    </FormItem>
                                </Col>
                            </Row>
                        </Form>
                    </div>
                </Panel>
                <Panel name="6">
                    网银到账查询（到账勾稽）
                    <div slot="content">
                        <Table border :columns="bankArriveColums" :data="bankArriveList">
                            <template slot-scope="{ row, index }" slot="receivingBank">
                                <span>{{setDictTitleByType("bankCode",row.receivingBank)}}</span>
                            </template>
                            <template slot-scope="{ row, index }" slot="receivedAmt">
                                <span>{{row.receivedAmt==""?"":row.receivedAmt.toFixed(2)}}</span>
                            </template>
                        </Table>
                    </div>
                </Panel>
            </Collapse>
            <UploadFileModal
                ref="uploadFileModal"
                :modal="isUploadFileModalOpen"
                @closeModal="closeModal"
                :param="fileParams"
                @asyncSaveFileFn="asyncSaveFileFn"
                :isPreview="true"
            />
        </Card>
    </div>

</template>

<script>
    import {
        getByTypes
    } from "_p/basic/api/admin/datadic";
    import {
        queryCorporateByCaseNo
    } from "@/projects/basic/api/contract/corporate/corporateTransferManagement";

    import {
        contractInfoForCorporate,
    } from "@/projects/basic/api/contract/common/contract-info/contract-info";

    import {
        queryBankArriveListByCaseNo,
    } from "@/projects/basic/api/contract/bank-arrive/bankArriveManagement";
    import {getApplyInfoById} from "@/projects/basic/api/contract/clearance/stay-settle";

    import approveHistory from "../common/approve-history/approve-history";
    import LeaseFileUpload from '_c/file-upload/index'
    import UploadFileModal from "_p/basic/pages/contract/common/uploadFileModal/uploadFileModal";
    import contractCurrentUser from "_p/basic/pages/contract/common/current-user/contractCurrentUser";
    export default {
        name: "detailForBusinessView",
        components: {
            approveHistory,
            UploadFileModal,
            LeaseFileUpload,
            contractCurrentUser
        },
        props: {
            obj: {
                caseNo: "",
                contractNo: "",
                id:"",
                caseType:"",
                prepaymentApplyId:"",
                type:Object
            }
        },
        data: function () {
            return {
                contractForm: {},
                contractFormValidate: {},
                isUploadFileModalOpen:false,
                fileParams:{},
                showPanel:[],

                approveHistoryObj:{
                    caseNo:"",
                    contractNo:""
                },
                dicKeys: [
                    "bankCode","businessSource","contractStatus","channelType","caseType","rateType","validOrInvalid"
                ],
                dataDic:{},
                caseInfo:{},
                prepaymentInfo:{},
                caseInfoFormValidate:{},
                contractInfo:{},
                contractInfoFormValidate:{},
                productInfo:{},
                bankArriveColums:[
                    {title: "网银编号",key: "ebankNo",minWidth: 160,align: "center"},
                    {title: "到账时间",key: "arrivalTime",minWidth: 100,align: "center"},
                    {title: "业务时间", key: "businessTime", minWidth: 100, align: "center"},
                    {title: "到账银行",key: "receivingBank",minWidth: 150,align: "center",slot: "receivingBank"},
                    {title: "到账银行账户",key: "bankAccount",minWidth: 150,align: "center"},
                    {title: "付款客户",key: "paymentCust",minWidth: 100,align: "center"},
                    {title: "客户账号",key: "custAccount",minWidth: 150,align: "center"},
                    {title: "到账金额",key: "receivedAmt",slot: "receivedAmt",minWidth: 100,align: "center"},
                    {title: "摘要",key: "summary",minWidth: 150,align: "center"},
                ],
                bankArriveList:[]
            }
        },
        mounted() {
            this.init();
        },
        methods: {
            initDataDic(){
                let self = this;
                getByTypes(this.dicKeys).then(res => {
                    if (res.code === "0000" && res.data) {
                        self.dataDic = res.data;
                    }
                });
            },
            getDic(v){
                let dic = []
                switch(v) {
                    case "bankCode":
                        dic = this.dataDic.bankCode;
                        break;
                    case "businessSource":
                        dic = this.dataDic.businessSource;
                        break;
                    case "contractStatus":
                        dic = this.dataDic.contractStatus;
                        break;
                    case "channelType":
                        dic = this.dataDic.channelType;
                        break;
                    case "caseType":
                        dic = this.dataDic.caseType;
                        break;
                    case "validOrInvalid":
                        dic = this.dataDic.validOrInvalid;
                        break;
                    default:
                }
                return dic;
            },
            setDictTitleByType(v1,v2){
                let dic = {}
                if(!this.getDic(v1)) return '';
                this.getDic(v1).forEach(column => {
                    if(column.value === v2){
                        dic = column;
                    }
                });
                return dic.title;
            },
            queryPrepaymentInfo(){
                if (!this.caseInfo.prepaymentApplyId){
                    this.caseInfo.prepaymentApplyId = this.obj.prepaymentApplyId;
                }
                getApplyInfoById({id:this.caseInfo.prepaymentApplyId}).then(res => {
                    if (res.code === "0000") {
                        this.prepaymentInfo = res.data;
                    }
                });
            },
            queryCaseInfo(){

                queryCorporateByCaseNo(this.obj.caseNo).then(res => {
                    if (res.code === "0000") {
                        this.caseInfo = res.data;
                        //加载提前还款信息
                        if("BEFORE_CHARGE" == this.obj.caseType){
                            this.queryPrepaymentInfo();
                        }
                        //加载网银到账信息
                        this.queryBankArriveList(this.caseInfo.id);
                    }
                });
            },
            queryContractInfo(){
                contractInfoForCorporate({contractNo:this.obj.contractNo}).then(res => {
                    if (res.code === "0000") {
                        this.contractInfo = res.data;
                    }
                });
            },
            queryBankArriveList(v){
                let params = {};
                if (v && v != ''){
                    params.caseId = v
                }else{
                    params.caseId = this.obj.id
                }
                queryBankArriveListByCaseNo(params).then(res => {
                    if (res.code === "0000") {
                        this.bankArriveList = res.data;
                    }
                });
            },
            openUploadModal() {
                this.fileParams = {
                    belongNo: this.caseInfo.contractNo,
                    busiNo:this.caseInfo.caseNo,
                    busiType: 'corporateTransfer',
                    busiData: {},
                    busiNodes:'corporateTransfer' //业务节点
                }
                this.isUploadFileModalOpen = true;
            },
            closeModal() {
                // 获取文件长度
                let l = this.$refs.uploadFileModal.getFileList()
                console.log(' 文件长度为：', l);

                this.isUploadFileModalOpen = false;
            },
            asyncSaveFileFn(data) {
                console.log('上传成功',data);
                this.$refs.formData.validate(valid => {
                    if (valid) {
                        let d = Object.assign({}, data, this.formData, this.oldData, this.Obj);

                        this.$emit(this.parentFuncName, d)
                        // this.$emit(funcName, d);
                    } else {
                        this.$Message.error("验证不通过!");
                        this.$emit("closeSpin");
                        verifyErrorToView(this.$refs.formData.fields);
                    }
                })
            },
            init(){
                //加载提前还款信息
                if("BEFORE_CHARGE" == this.obj.caseType){
                    this.showPanel = [2,3,4,5,6];
                }else{
                    this.showPanel = [2,3,5,6]
                }
                //加载数字字典
                this.initDataDic();
                //加载合同信息
                this.queryContractInfo();
                //操作历史记录数据加载
                this.approveHistoryObj.caseNo = this.obj.caseNo;
                this.approveHistoryObj.contractNo = this.obj.contractNo;
                //加载对公结算案件详情
                this.queryCaseInfo();
            },
        }
    }
</script>

<style scoped>

</style>
